﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace MyLib.Web.UI {
	/// <summary>
	/// 
	/// </summary>
	public class MyPanelContainerDesigner : ContainerControlDesigner {
		/// <summary>
		/// 
		/// </summary>
		/// <param name="styleAttributes"></param>
		protected override void AddDesignTimeCssAttributes(IDictionary styleAttributes) {
			MyPanel component = (MyPanel)base.Component;
			switch (component.Direction) {
				case ContentDirection.LeftToRight:
					styleAttributes["direction"] = "ltr";
					break;

				case ContentDirection.RightToLeft:
					styleAttributes["direction"] = "rtl";
					break;
			}
			string backImageUrl = component.BackImageUrl;
			if (backImageUrl.Trim().Length > 0) {
				IUrlResolutionService service = (IUrlResolutionService)this.GetService(typeof(IUrlResolutionService));
				if (service != null) {
					backImageUrl = service.ResolveClientUrl(backImageUrl);
					styleAttributes["background-image"] = "url(" + backImageUrl + ")";
				}
			}
			switch (component.ScrollBars) {
				case ScrollBars.Horizontal:
					styleAttributes["overflow-x"] = "scroll";
					break;
				case ScrollBars.Vertical:
					styleAttributes["overflow-y"] = "scroll";
					break;
				case ScrollBars.Both:
					styleAttributes["overflow"] = "scroll";
					break;
				case ScrollBars.Auto:
					styleAttributes["overflow"] = "auto";
					break;
			}
			HorizontalAlign horizontalAlign = component.HorizontalAlign;
			if (horizontalAlign != HorizontalAlign.NotSet) {
				TypeConverter converter = TypeDescriptor.GetConverter(typeof(HorizontalAlign));
				styleAttributes["text-align"] = converter.ConvertToInvariantString(horizontalAlign).ToLowerInvariant();
			}
			base.AddDesignTimeCssAttributes(styleAttributes);
		}

		/// <summary>
		/// 
		/// </summary>
		public override string FrameCaption {
			get {
				return ((MyPanel)base.Component).Title;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		protected override bool UsePreviewControl {
			get {
				return true;
			}
		}
	} // end of MyPanelContainerDesigner.
}
